﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using DBSourceToolsLib;

namespace DBSourceTools
{
    public partial class MainPanelForm : DockContent, DBSourceToolsLib.Interfaces.ISourceEditorSubject
    {
        protected string m_DatabaseName;
        protected string m_ObjectType;
        protected string m_Name;
        protected DBSourceToolsLib.Interfaces.ISourceEditorObserver m_Observer;
        public MainPanelForm()
        {
            InitializeComponent();
        }

        public MainPanelForm(string strDBName, string strObjType, string strName)
        {
            this.m_DatabaseName = strDBName;
            this.m_ObjectType = strObjType;
            this.m_Name = strName;

            InitializeComponent();
        }

        #region ISourceEditorSubject Members

        public void RegisterInterestInSourceEditor(DBSourceToolsLib.Interfaces.ISourceEditorObserver observer)
        {
            this.m_Observer = observer;
        }

        #endregion

        private void OnFormClosing(object sender, FormClosingEventArgs e)
        {
            this.m_Observer.NotifyEvent(this.m_DatabaseName, this.m_ObjectType, this.m_Name
                , DBSourceToolsLib.Interfaces.SourceEditorEvent.Close, null);

        }

        private void OnFormActivated(object sender, EventArgs e)
        {
            this.m_Observer.NotifyEvent(this.m_DatabaseName, this.m_ObjectType, this.m_Name
                , DBSourceToolsLib.Interfaces.SourceEditorEvent.IsCurrent, null);

        }

        public string WindowKey
        {
            get { return m_DatabaseName + "." + m_ObjectType + "." + m_Name; }
        }

    }
}
